#include <stdio.h>
#include <stdint.h>
#include <inttypes.h>
#include <math.h>

int is_prime(int64_t num) {
    if (num == 0 || num == 1) {
        return 0;
    }
    for(int64_t i = 2; i * i <= num; i == 2 ? (i = 3) : (i += 2)) {
        //printf("num: %ld, i: %ld, num %% i: %ld\n", num, i, num % i);
        if (num % i == 0) {
            return 0;
        }
    }
    return 1;
}

int is_flawless_prime(int64_t num) {
    if (num < 10) {
        return is_prime(num);
    }
    if (!is_prime(num)) {
        return 0;
    }
    int64_t len = 1, len_ex = 1;
    while (len_ex <= num) {
        len++;
        len_ex *= 10;
    }
    len--;
    for(; len > 2; len--, len_ex /= 10) {
        int64_t cutted = num % (len_ex / 10);
        //printf("num: %" PRId64 ", len: %" PRId64 ", len_ex: %" PRId64 ", cutted: %" PRId64 "\n", num, len, len_ex, cutted);
        if (!is_prime(cutted) || cutted < (len_ex / 100)) {
            return 0;
        }
    }
    return is_prime(num % 10);
}

int main(void) {
    int t;
    scanf("%d", &t);
    for(int i = 0; i < t; i++) {
        int64_t num;
        scanf("%" SCNd64, &num);
        puts(is_flawless_prime(num) ? "Yes" : "No");
        //printf(is_flawless_prime(num) ? "Yes %" PRId64 "\n" : "No %" PRId64 "\n", num);
    }
    return 0;
}
